package com.interesting.client.UI.setting;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;

import com.ant.liao.GifView;
import com.interesting.R;
import com.interesting.base.core.BaseActivity;
import com.interesting.base.download.HttpDownload;

/** gif显示 */
public class GifActivity extends BaseActivity {

	private GifView gifView;
	private String url;
	private final static String path = "/gif/";
	private final static String name = ".gif";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gif_activity);

		gifView = (GifView) findViewById(R.id.gif_activity_gif);

		new downloadAsync().execute(url, "xx");
	}

	private class downloadAsync extends AsyncTask<String, Void, String> {

		protected String doInBackground(String... params) {
			HttpDownload httpDownloader = new HttpDownload();
			return httpDownloader.downFile(params[0], path, params[1] + name);// gif文件名命名有问题，需改善

		}

		@Override
		protected void onPostExecute(String result) {
			String path = Environment.getExternalStorageDirectory() + result;
			if (result != "-1") {
				gifView.setGifImage(path);
				gifView.setLoopAnimation();
			}
			super.onPostExecute(result);
		}
	}

	@Override
	protected void onPause() {
		gifView.destroy();
		super.onPause();
	}

	@Override
	protected void onStop() {
		super.onStop();
	}

}
